<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * @category   Hamania
 * @package    Hamania_CashOnRelay
 * @copyright  Copyright (c) 2010 Hamania Medien GmbH & Co. KG (http://www.phoenix-medien.de)
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
?>
<?php
$_code		= $this->getMethodCode();
$_extra_fee	= $this->getMethod()->getAddressCosts($this->getShippingAddress());

$_extra_fee_excl = $this->convertPrice(Mage::helper('cashonrelay')->getCorPrice($_extra_fee, $this->helper('cashonrelay')->displayCorFeeIncludingTax(), $this->getShippingAddress()), true);
$_extra_fee_incl = $this->convertPrice(Mage::helper('cashonrelay')->getCorPrice($_extra_fee, true, $this->getShippingAddress()), true);

$_corFeeStr = $_extra_fee_excl;
if ($this->helper('cashonrelay')->displayCorBothPrices() && ($_extra_fee_incl != $_extra_fee_excl)) {
	$_corFeeStr .= ' ('.$this->__('Incl. Tax').' '.$_extra_fee_incl.')';
}
?>
<?php if($this->getMethod()->getCustomText() || $_extra_fee || Mage::getStoreConfig('payment/cashonrelay/display_zero_fee')): ?>
<fieldset class="form-list">
	<ul id="payment_form_<?php echo $_code ?>" style="display:none;">
  	<?php if($_extra_fee || Mage::getStoreConfig('payment/cashonrelay/display_zero_fee')): ?>
		<li>
			<?php echo $this->__('You will be charged an extra fee of %s.', $_corFeeStr) ?>
		</li>
    <?php endif; ?>    
		
		<?php if ($this->getMethod()->getCustomText()): ?>
		<li>
			<?php echo $this->getMethod()->getCustomText() ?>
		</li>
		<?php endif; ?>  
		  
		<li>
    		<!--label for="<?php echo $_code ?>_relay_id" class="required"><em>*</em><?php echo $this->__('Select your relay')?></label-->
        <div class="input-box">
            <select id="<?php echo $_code ?>_relay_id" name="payment[relay_id]" class="required-entry validate-relay-type-select">
                <option value=""><?php echo $this->__('--Please Select Your Relay--')?></option>                     
								
            		<?php $_selectId = $this->getInfoData('relay_id') ?>
            		<?php foreach ($this->getAvailableRelays() as $_relayId => $_relayName): ?>
                <option value="<?php echo $_relayId ?>"<?php if($_relayId==$_selectId): ?> selected="selected"<?php endif ?>><?php echo $_relayName ?></option>
            		<?php endforeach ?>
            </select>
						<span style="padding: 0 5px;"><a href="#" onclick="" id="show_gmap"><?php echo __("view gmap")?></a></span>
        </div>
				<div id="<?php echo $_code ?>_gmap" style="display:none;position: absolute;z-index: 99999; top: 0px; left: 127px; ">
					<div class="modal_top"></div>
					<a id="hide_gmap" href="javascript:void(0);">
						<img id="close" class="modal_close" height="39" width="39" alt="" src="<?php echo $this->getSkinUrl('images/close.gif') ?>">
					</a>
					<div class="modal_content">
						<div id="<?php echo $_code ?>_relay_gmap" style="height:200px;">
							&nbsp;
						</div>
					</div>
					
					<div class="modal_bottom"></div>
				</div>
    </li>
	</ul>
</fieldset>
<script src="http://maps.google.com/maps/api/js?sensor=false&language=en" type="text/javascript"></script>

<script type="text/javascript">
//<![CDATA[
	var geocoder;
	var map;
	geocoder = new google.maps.Geocoder();
	var latlng = new google.maps.LatLng(21.015291, 105.838509);
	var myOptions = {
		zoom: 8,
		center: latlng,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	}
	map = new google.maps.Map(document.getElementById("<?php echo $_code ?>_relay_gmap"), myOptions);
	var address = "" ;

	<?php
		$addr = $this->getShippingAddress() ;
		if(empty($addr)):
		$addr = $this->getBillingAddress() ;
		endif;
		
		if(!empty($addr)):
				echo "address =\"".implode(",",$addr->getStreet()).",".$addr->getCity().",Vietnam\"; " ;
		endif ;
	?>
	
	if(address !="")
	geocoder.geocode( { 'address': address}, function(results, status) {
		if (status == google.maps.GeocoderStatus.OK) {
			map.setCenter(results[0].geometry.location);
			var marker = new google.maps.Marker({
			map: map,
			position: results[0].geometry.location
		});
		} else {
			alert("Your address could not be found");// + status);
		}
	}); 
//]]>
</script>
<?php endif; ?>